import axios from "axios";
import NProgress from 'nprogress';
var baseUrl = "http://api.cat-shop.penkuoer.com";
// 添加请求拦截器
axios.interceptors.request.use(function(config) {
	// 在发送请求之前做些什么
	config.headers.common['authorization'] = "Bearer "+localStorage.getItem('token')
	
	NProgress.start()
	return config;
}, function(error) {
	// 对请求错误做些什么
	return Promise.reject(error);
});

// 添加响应拦截器
axios.interceptors.response.use(function(response) {
	// 对响应数据做点什么
	NProgress.done()
	return response;
}, function(error) {
	// 对响应错误做点什么
	return Promise.reject(error);
});


export const GET = (url, params) => {
  return axios.get(`${baseUrl}${url}`, { params }).then(data => data);
};

export const POST = (url, params) => {
  return axios.post(`${baseUrl}${url}`, params).then(data => data);
};

export const PUT = (url,params)=>{
	return axios.put(`${baseUrl}${url}`,params).then((data)=>data)
}

export const DELETE = (url,params)=>{
	return axios.delete(`${baseUrl}${url}`,params).then((data)=>data)
}
